package pl.edu.agh.hollonCommision.graph.connectionModel;

import dtp.commission.Commission;

public class LocationAndTimeProximityConnection implements IConnectionModel {

	private double distance;
	private double time;
	public LocationAndTimeProximityConnection(double distance, double time) {
		this.distance = distance;
		this.time = time;
	}

	@Override
	public boolean areConnected(Commission commission, Commission commission2) {
		double tmpDistance;
		double x = commission.getPickupX() - commission2.getPickupX();
		double y = commission.getPickupY() - commission2.getPickupY();
		tmpDistance = x * x + y * y;

		x = commission.getPickupX() - commission2.getDeliveryX();
		y = commission.getPickupY() - commission2.getDeliveryY();
		tmpDistance = Math.min(tmpDistance, x * x + y * y);
		
		x = commission.getDeliveryX() - commission2.getPickupX();
		y = commission.getDeliveryY() - commission2.getPickupY();
		tmpDistance = Math.min(tmpDistance, x * x + y * y);
		
		x = commission.getDeliveryX() - commission2.getDeliveryX();
		y = commission.getDeliveryY() - commission2.getDeliveryY();
		tmpDistance = Math.min(tmpDistance, x * x + y * y);
		double timeInterval = Math.abs(commission.getDeliveryTime1() - commission2.getDeliveryTime1());
		timeInterval = Math.min(timeInterval, Math.abs(commission.getPickupTime1() - commission2.getPickupTime1()));
		timeInterval = Math.min(timeInterval, Math.abs(commission.getPickupTime1() - commission2.getDeliveryTime1()));
		timeInterval = Math.min(timeInterval, Math.abs(commission.getDeliveryTime1() - commission2.getPickupTime1()));
		return (Math.sqrt(tmpDistance) < distance ) && (timeInterval < time);
	}

}
